<?php
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$dtype_id = $_POST['dtype_id'];
		$brand_id = $_POST['brand_id'];
		$product_id = $_POST['product_id'];
		$color_id = $_POST['color_id'];
		$size_id = $_POST['size_id'];
		$season_id = $_POST['season_id'];
		
		$ditem_value = '';
		foreach($_POST['ditem_value'] as $v){
			$ditem_value .= $v.'{,}';
		}
		$ditem_value = substr($ditem_value,0,-3);
		
		$ditem_type = '';
		foreach($_POST['ditem_type'] as $v){
			$ditem_type .= $v.'{,}';
		}
		$ditem_type = substr($ditem_type,0,-3);
		
		$date_start = strtotime($_POST['date_start']);
		$date_finish = strtotime($_POST['date_finish']);
		$detail = $_POST['detail'];
		$sql = "INSERT INTO `tbl_discount_item` (`dtype_id`, `brand_id`, `product_id`, `color_id`, `size_id`, `season_id`, `active`, `ditem_value`, `ditem_type`, `date_start`, `date_finish`, `detail`) VALUES ('$dtype_id', '$brand_id', '$product_id', '$color_id', '$size_id', '$season_id', '1', '$ditem_value', '$ditem_type', '$date_start', '$date_finish' , '$detail');";
		mysql_query($sql);
		redirect($dtype_id);
		exit;
	}
	
	$dtype_id = 3;
	$brand_option = '';
	$sql = "SELECT brand_id , title FROM tbl_brand ORDER BY title";
	$result = mysql_query($sql)or die($sql);
	while($line = mysql_fetch_assoc($result)){
		$brand_option .= '<option value="'.$line['brand_id'].'">'.$line['title'].'</option>';
	}
	
	$value_option_1 = '';
	$i = 0;
	for($i;$i<=100;$i++){
		$value_option_1 .= "<option value='{$i}'>{$i}</option>";
	}
	$value_option_2 = '';
	$i = 0;
	for($i;$i<=100;$i++){
		$value_option_2 .= "<option value='{$i}'>{$i}</option>";
	}
	$value_option_3 = '';
	$i = 0;
	for($i;$i<=100;$i++){
		$value_option_3 .= "<option value='{$i}'>{$i}</option>";
	}
	
	$piece_option = $value_option_1;
	
	$date_start = date('d-m-Y');
	$date_finish = date('d-m-Y',strtotime(date("d-m-Y") . " +1 month"));
	
	$tp->apply();
?>